// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let { OPENID } = wxContext
  let { page, pageSize } = event
  const db = cloud.database()
  var cardList = []

  let skip = (page - 1) * pageSize
  let cards = await db.collection('cards').skip(skip).limit(pageSize).orderBy('systemTime', 'desc').get()
  if (cards.data.length > 0) {
    cardList = cards.data
  }

  return {
    cardList
  }
}